/*
 * HtmlHeaderBuilder.java
 *
 *  created: 20.8.2011
 *  charset: UTF-8
 *  license: MIT (X11) (See LICENSE file for full license)
 */
package cz.mp.k3bg.core;

import cz.mp.k3bg.Application;
import static cz.mp.k3bg.Application.EOL;
import java.nio.charset.Charset;

/**
 * {@code HtmlHeaderBuilder} sestaví hlavičku a patičku HTML souboru.
 * Pomocná třída.
 * 
 * @author Martin Pokorný
 * @version 0.1
 */
public class HtmlHeaderBuilder {

//    private static final boolean DEBUG = false;
//    private static final Logger logger =
//            LoggerManager.getLogger(HtmlHeaderBuilder.class, DEBUG);
    
    private String charsetName = Application.PREFERRED_CHARSET;
            
    private String stylesheetFileName = BookFiles.DEFAULT_STYLE_FILENAME;
            
    // -----
            
    /** */
    public HtmlHeaderBuilder() {
    }

    /**
     * 
     * @param charsetName 
     */
    public void setCharsetName(String charsetName) {
        this.charsetName = charsetName;
    }
    
    /**
     * 
     * @param charset 
     */
    public void setCharset(Charset charset) {
        this.charsetName = charset.name();
    }

    /**
     * 
     * @param stylesheetFileName 
     */
    public void setStylesheetFilePathName(String stylesheetFileName) {
        if (stylesheetFileName == null) {
            throw new IllegalArgumentException("stylesheetFileName=null");
        }
        this.stylesheetFileName = stylesheetFileName;
    }

    /**
     * 
     * @return 
     */
    public String getStylesheetFileName() {
        return stylesheetFileName;
    }
    
    /**
     * 
     * @return 
     */
    public String createHtmlHeader() {        
        StringBuilder sb = new StringBuilder(512);
        // HTML
        sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" ")
                .append("\"http://www.w3.org/TR/html4/loose.dtd\">")
                .append(EOL);
        sb.append("<html>").append(EOL);
        sb.append(EOL);
        sb.append("<head>").append(EOL);
        sb.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=")
                .append(charsetName).append("\">").append(EOL);
        sb.append("<link ").append("rel=\"stylesheet\" ")
                .append("href=\"")
                .append(stylesheetFileName).append("\" ")
                .append("type=\"text/css\">").append(EOL);
        sb.append("<title></title>").append(EOL);
        sb.append("</head>").append(EOL);
        sb.append(EOL);
        sb.append("<body>").append(EOL);
        sb.append(EOL);
        return sb.toString();
    }
    
    /**
     * 
     * @return 
     */
    public String createHtmlFooter() {
        StringBuilder sb = new StringBuilder(64);        
        sb.append("</body>").append(EOL);
        sb.append("</html>").append(EOL);        
        return sb.toString();
    }
    
}   // HtmlHeaderBuilder
